const { v4: uuidv4 } = require("uuid");

/**
 * 角色-菜单中间表模型
 */
module.exports = (app) => {
    const { STRING, BIGINT, BOOLEAN, DATE, DOUBLE ,UUID} = app.Sequelize
    const RolePermission = app.model.define(
      'role_permission',
      {
        id: {
            type: UUID,
            unique: true,
            primaryKey: true,
            allowNull: false,
            defaultValue: () => {
              return uuidv4().replace(/-/g, "");
            },
          },
        permissionId: {
          type:UUID,
          allowNull: true,
        },
        roleId: {
          type: UUID,
          allowNull: true,
        },
        created: {
          type: DATE,
          allowNull: true,
          defaultValue: app.Sequelize.NOW,
        },
        creator: {
          type: STRING(36),
          allowNull: true,
        },
        edited: {
          type: DATE,
          allowNull: true,
        },
        editor: {
          type: STRING(36),
          allowNull: true,
        },
        deleted: {
          type: DOUBLE,
          allowNull: true,
        },
      },
      {
        freezeTableName: true, // Model 对应的表名将与model名相同
        timestamps: false,
      }
    )
  
    return RolePermission
  }